/**
 * 着陆页使用
 */
if (!window.shbly_func) {
	window.shbly_func = {
		parseURL: function(url) {
			var a = document.createElement('a');
			a.href = url;
			return {
				source: url,
				protocol: a.protocol.replace(':', ''),
				host: a.hostname,
				port: a.port,
				query: a.search,
				params: (function() {
					var ret = {},
						seg = a.search.replace(/^\?/, '').split('&'),
						len = seg.length,
						i = 0,
						s;
					for (; i < len; i++) {
						if (!seg[i]) {
							continue;
						}
						s = seg[i].split('=');
						ret[s[0]] = s[1];
					}
					return ret;
				})(),
				file: (a.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1],
				hash: a.hash.replace('#', ''),
				path: a.pathname.replace(/^([^\/])/, '/$1'),
				relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1],
				segments: a.pathname.replace(/^\//, '').split('/')
			};
		},

		post: function(url, data, fn, is_as) {
			var obj = new XMLHttpRequest();
			obj.open("POST", url, is_as);
			obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			obj.onreadystatechange = function() {
				if (obj.readyState == 4 && (obj.status == 200 || obj.status == 304)) {
					fn.call(this, obj.responseText);
				}
			};
			obj.send(data);
		}
	}
	var $data = {
			"sn": "<{$sn}>"
		},
		$refer = document.referrer,
		$shb_showsec = '0';
	if (!$refer) {
		try {
			if (window.opener) {
				$refer = window.opener.location.href;
			}
		} catch (e) {}
	}
	var $url = shbly_func.parseURL($refer);
	$data["wd"] = $url.params.wd || $url.params.word || $url.params.query || $url.params.keywod || $url.params.keyword ||
		$url.params.word1 || $url.params.title || '';
	$data["title"] = document.title;
	$data["href"] = window.location.href;
	$data["user_agent"] = navigator.userAgent;
	$data["referrer"] = document.referrer;
	$data["host"] = $url.host;
	$data["deal_name"] = 'in_web';
	$data["platform"] = navigator.platform;
	var $wd_temp = '';
	try {
		if (/.sm.cn$/i.test($url.host)) {
			$data["wd"] = $url.params.q || '';
		}
		if (/.so.com$/i.test($url.host)) {
			$data["wd"] = $url.params.q || '';
		}
	} catch (err) {}
	if ($data["wd"].length <= 0)
		$data["wd"] = $data["title"];
	$data["wd"] = decodeURIComponent($data["wd"]);

	if ($data["wd"].indexOf('%') >= 0)
		$data["wd"] = decodeURIComponent($data["wd"]);

	if ($data["wd"].length > 0) {
		$data["enwd"] = encodeURIComponent($data["wd"]);
	} else {
		$data["enwd"] = '';
	}
	// var shb_isclick = '1';
	// if (shb_isclick == '1') {
	// var $dp = encodeURIComponent(window.location.href);
	// try {
	// openZoosUrl('fchatwin', '&inf=c004&shbkwod=111' + '&e=777'+$data["wd"]+'&inf=test3');
	// } catch (err) {
	// window.location.href = 'http://<{$pre}>.zoosnet.net/LR/Chatpre.aspx?id=<{$swt_id}>&lng=cn&p=X-S-H-B&inf=c005&shbkwod=111' + '&e=777'+$data["wd"]+'&inf=test3' + '&p=' + $dp + lr_getrefer();
	// }
	// }
	if (typeof(jQuery) == 'undefined') {
		var script = document.createElement("script");
		script.setAttribute("type", "text/javascript");
		script.setAttribute("src", "https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js");
		document.getElementsByTagName("head")[0].appendChild(script);
	}

	//发送数据
	if ($shb_showsec.length > 0) {
		$shb_showsec = parseInt($shb_showsec);
	} else
		$shb_showsec = 0;

	if ($shb_showsec > 0) {
		setTimeout("ly_get_eval($data)", $shb_showsec);
	} else {
		ly_get_eval($data);
	}

}

function lr_getrefer() {
	var ur = document.referrer;
	var i = ur.lastIndexOf('.');
	return '&rf1=' + escape(ur.substring(0, i)) + '&rf2=' + escape(ur.substr(i));
}

function ly_get_eval($d) {
	shbly_func.post("__HOST__/api/zly", JSON.stringify($d), function($rs) {
		$rs = JSON.parse($rs);
		if ($rs['code'] == '0') {
			insertswtChatTjJs();
			eval($rs['do'])
		}
	}, true);
}

function insertswtChatTjJs() {
	var swt_id = '<{$swt_id}>';
	try {
		if ($("textarea")) $("textarea").on("click").on("click", '');
	} catch (e) {}
	if (typeof(LR_sysurl) == "undefined" || LR_websiteid.toLowerCase() != swt_id.toLowerCase()) {
		var _wocguWQc = document.createElement("script");
		_wocguWQc.setAttribute("charset", "utf-8");
		_wocguWQc.setAttribute("src", "https://<{$pre}>.zoosnet.net/JS/LsJS.aspx?siteid=<{$swt_id}>&lng=cn");
		if (document.body) {
			try {
				document.body.appendChild(_wocguWQc);
			} catch (e) {
				document.documentElement.appendChild(_wocguWQc);
			}
		} else {
			var heads = document.getElementsByTagName("head");
			if (heads.length) heads[0].appendChild(_wocguWQc);
		}
	}
	window.LR_msg = '';
	window.LR_explain = '';
	LiveAutoInvite1 = undefined;
	window.LR_CheckImgJS = function(w, w1, w2, w3) {
		window.LR_msg = '';
		window.LR_explain = '';
		LiveAutoInvite1 = undefined;
		LR_inviteimgJS = 1;
		var swtkrsm = '1';
		if (swtkrsm == '2')
			swtkrsm = 'shbkwd';
		else
			swtkrsm = 'e';
		if (!w) {
			return;
		}
		if (w == 28) {
			return;
		}
		if (checkcount == -1 && w != 6)
			return;
		if (w > 0) {
			if (w == 2) {
				LR_gstate = 1;
				if (LR_istate < 2) {
					clearinviteTimeout();
					LR_istate = 2;
					window.focus();
					openZoosUrl('fchatwin', '&inf=c003&shbkwod=1112&' + swtkrsm + '=777' + $data["enwd"]);
					return;
				}
			}
			if (w == 8) {
				LR_gstate = 1;
				if (LR_istate > -1) {
					clearinviteTimeout();
					LR_istate = 1;
					openZoosUrl('fchatwin', '&inf=c002&shbkwod=113&' + swtkrsm + '=777' + $data["enwd"]);
				}
				return;
			}
			if (w == 4) {
				LR_gstate = 0;
				if (LR_istate > 1) {
					LR_istate = 0;
				}
				LR_nextinvite();
				//openZoosUrl('fchatwin','&shbkwod=111&'+swtkrsm+'=777'+$data["enwd"]);
				return;
			}
			if (w == 5) {
				clearinviteTimeout();
				if (LR_istate > 0) {
					LR_istate = 0;
				}
				if (LR_gstate != 2) {
					LR_gstate = 2;
					LR_SetCookie('LR_lastchat', '1', 720);
				}

				if (LR_GetObj('LRMINIBar') == null && ((LR_pm001 && LR_pm002) || LR_pm009)) {
					LR_HideInvite();
					LR_istate = 1;
					openZoosUrl('fchatwin', '&inf=c001&shbkwod=111&' + swtkrsm + '=777' + $data["enwd"]);
				}
				return;
			}
			if (w == 7) {
				LR_gstate = -1;
				if (LR_istate > 1) {
					LR_istate = 0;
				}
				LiveReceptionCode_isonline = 0;
				if (typeof(LR_offline) == 'function')
					LR_offline();
				LR_Floaters[0].pms['html'] = LR_buildfloat();
				LR_Floaters[0].imageTimer(true);
				return;
			}
			if (w == 1) {
				if (LR_gstate == 1)
					return;
				checkcount = 2;
				LR_invite0 = w1;
				LR_invite1 = w2;
				LR_invitef();
			}
		}
	}
}
